package model

import (
	"kpt-dtm/model/yyn"
	"strings"
)

type Surplus struct {
	Id           int64  `json:"id" `
	PastureId    int64  `json:"pasture_id"`
	PenId        string `json:"pen_id" `
	PenName      string `json:"pen_name" `
	TotalRefused string `json:"total_refused" `
	RefusedDate  string `json:"refused_date" `
	CreatedAt    int64  `json:"created_at"`
	UpdatedAt    int64  `json:"updated_at"`
}

func (s *Surplus) TableName() string {
	return "d_surplus"
}

func NewSurplus(pastureId int64, penId, penName, totalRefused, refuserDate string) *Surplus {
	return &Surplus{
		PastureId:    pastureId,
		PenId:        penId,
		PenName:      penName,
		TotalRefused: totalRefused,
		RefusedDate:  refuserDate,
	}
}

func NewSurplusList(pastureId int64, res []*yyn.MqttOverPlusData) []*Surplus {
	surplusList := make([]*Surplus, 0)
	for _, v := range res {
		surplusList = append(surplusList, NewSurplus(pastureId, strings.TrimSpace(v.PenId), strings.TrimSpace(v.PenName), v.ActualWeight, v.StartTime))
	}
	return surplusList
}
